package 机试题16年;

import java.util.Scanner;

/**
 * Created by hest0 on 2017/4/19.
 */
public class 旅途醋溜到楚楚街 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            //车站的权重
            int[] weight = new int[n + 1];
            //联通的图
            int[][] road = new int[n + 1][n + 1];

            for (int i = 1; i <= n; i++) {
                weight[i] = sc.nextInt();
            }

            for (int i = 0; i < m; i++) {
                int x = sc.nextInt();
                int y = sc.nextInt();
                road[x][y] = 1;
                road[y][x] = 1;
            }

            System.out.println(travel(n, m, weight, road));
        }
        sc.close();
    }

    private static int travel(int n, int m, int[] weight, int[][] road) {

        //visited节点是不是已经访问过
        //dp是最后的结果
        boolean[] visited = new boolean[n + 1];
        int[] dp = new int[n + 1];

        for (int i = 0; i <= n; i++) {
            dp[i] = Integer.MAX_VALUE;
        }

        dp[1] = weight[1];
        visited[1] = true;

        int tmp_i = 1;

        for (int i = 0; i < n - 1; i++) {

            for (int j = 1; j <= n; j++)
                dp[j] = (!visited[j] && road[tmp_i][j] == 1) ? Math.min(dp[j], dp[tmp_i] + weight[j]) : dp[j];

            int tmp_min = Integer.MAX_VALUE;

            for (int j = 1; j <= n; j++) {
                if (!visited[j] && dp[j] <= tmp_min) {
                    tmp_i = j;
                    tmp_min = dp[j];
                }
            }

            visited[tmp_i] = true;
        }

        return dp[n];
    }

}
